package guiwithbananaandhungrymonkeys;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;

import modelewithstatemachine.ClientAroundStateMachineOMGIMSURROUNDED;
import modelewithstatemachine.ManagerWithTaxiWithStateMachinePleaseIWantALongerName;
import modelewithstatemachine.TaxiWithStateMachine;

public class Ville extends JPanel {
	private static final long serialVersionUID = 1L;
	
	public static final int CITY_RADIUS = 280;
	int realCityRadius;
	private Trotteuse trot = new Trotteuse(10, 10, 151, 15);
	
	public void paintComponent(Graphics g){
		int x_center = (int) this.getParent().getSize().getWidth()/2;
		int y_center = (int) this.getParent().getSize().getHeight()/2;
		realCityRadius = ManagerWithTaxiWithStateMachinePleaseIWantALongerName.getCityRadius();
		
		g.setColor(Color.WHITE);
		g.fillOval((int) (x_center - CITY_RADIUS), 
					(int) (y_center - CITY_RADIUS), 
					(int) (2*CITY_RADIUS), 
					(int) (2*CITY_RADIUS));
        
        for(ClientAroundStateMachineOMGIMSURROUNDED c : ManagerWithTaxiWithStateMachinePleaseIWantALongerName.getClients()) {
        	//Pour voir les clients
        	g.setColor(Color.RED);
        	g.fillOval(x_center + (int)(c.getX()*((double)CITY_RADIUS/realCityRadius)), 
        				y_center + (int)(c.getY()*((double)CITY_RADIUS/realCityRadius)), 
        				5, 
        				5);
        }  
        
        for(TaxiWithStateMachine t : ManagerWithTaxiWithStateMachinePleaseIWantALongerName.getTaxis()) {
        	//Pour voir les taxis
        	g.setColor(Color.BLUE);
        	g.fillOval(x_center + (int)(t.getX()*((double)CITY_RADIUS/(double)realCityRadius)), 
        				y_center + (int)(t.getY()*((double)CITY_RADIUS/(double)realCityRadius)), 
        				5, 
        				5);
        	if(t.hasClients())
        		g.drawString(String.valueOf(t.getClientsCount()), x_center + (int)(t.getX()*((double)CITY_RADIUS/(double)realCityRadius) + 1), 
        				y_center + (int)(t.getY()*((double)CITY_RADIUS/(double)realCityRadius)) - 1);
        	
        	//Pour voir où va le taxi
        	g.setColor(Color.BLUE);
        	g.drawLine(x_center + (int)(t.getX()*((double)CITY_RADIUS/(double)realCityRadius)), 
        				y_center + (int)(t.getY()*((double)CITY_RADIUS/(double)realCityRadius)),
        				x_center + (int)(t.getXDest()*((double)CITY_RADIUS/(double)realCityRadius)),
        				y_center + (int)(t.getYDest()*((double)CITY_RADIUS/(double)realCityRadius)));
        }
        
        trot.computeAndDraw(g);
	}               
}